package com.oraro.paygatewaybiz.module.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oraro.paygatewaybiz.module.dao.ChannelDao;
import com.oraro.paygatewaybiz.module.entity.ChannelEntity;
import com.oraro.paygatewaybiz.module.service.ChannelService;
import com.oraro.paygatewaybiz.utils.Query;
import com.oraro.paygatewaybiz.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("channelService")
public class ChannelServiceImpl extends ServiceImpl<ChannelDao, ChannelEntity> implements ChannelService {

    @Override
    public IPage<ChannelEntity> queryPage(Map<String, Object> params) {
        String channelInfo = (String)params.get("channelInfo");
        Long mchId = (Long)params.get("mchId");
        IPage<ChannelEntity> page = this.page(
                new Query<ChannelEntity>(params).getPage(),
                new QueryWrapper<ChannelEntity>().like(channelInfo != null, "channel_info", channelInfo)
                    .eq(mchId != null, "mch_id", mchId)
        );
        return page;
    }

    @Override
    public ChannelEntity selectById (Long channelId) {
        return baseMapper.selectByChannelId(channelId);
    }

    @Override
    public ChannelEntity selectByMchAndType(Long mchId, String channelType) {
        return baseMapper.selectByMchAndType(mchId, channelType);
    }

    @Override
    public List<String> getChannelType(Long mchId) {
        return baseMapper.getChannelType(mchId);
    }

    @Override
    public ChannelEntity getChannelByWXMch(String wxMchId, String appId) {
        return baseMapper.getChannelByWXMch(wxMchId, appId);
    }

    @Override
    public ChannelEntity getChannelByAppId(String appId) {
        return baseMapper.getChannelByAppId(appId);
    }


}
